﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DataTool
{
    class CFileWriter
    {
        Stream m_pFile;
        public static CFileWriter Open(string filename)
        {
            CFileWriter pFile = new CFileWriter();
            pFile.m_pFile = new FileStream(filename, FileMode.CreateNew, FileAccess.Write);            
            return pFile;
        }
        public void Release()
        {
            if (m_pFile != null)
            {
                m_pFile.Close();
                m_pFile = null;
            }
        }

        public void WriteInt(int out_pData)
        {
            Write(BitConverter.GetBytes(out_pData));
        }
        public void WriteShort(short out_pData)
        {
            Write(BitConverter.GetBytes(out_pData));            
        }
        public void WriteByte(byte out_pData)
        {
            m_pFile.WriteByte(out_pData);
        }
        public void Write(int[] buff)
        {
            if (buff != null)
            {
                byte[] tmpOutData = new byte[buff.Length * 4];
                Buffer.BlockCopy(buff, 0, tmpOutData, 0, buff.Length * 4);
                Write(tmpOutData);
            }
        }
        public void Write(short[] buff)
        {
            if (buff != null)
            {
                byte[] tmpOutData = new byte[buff.Length*2];
                Buffer.BlockCopy(buff, 0, tmpOutData, 0, buff.Length * 2);
                Write(tmpOutData);
            }
        }
        public void Write(byte[] buff)
        {
            if (buff != null)
                Write(buff, 0, buff.Length);
        }
        public void Write(byte[] buff,int off, int size)
        {
            m_pFile.Write(buff, off, size);
        }

    }
}
